<?php
include_once("../includes/page_utf_class.php");
include("../lang/cn/company_type_config.php");
include_once("../module/product/includes/plugin_tarento_class.php");

$tarento = new Tarento();

if($_GET['act'] && $_GET['act']=='ajax_get_tarento'){
	$list = array();
	if ($_POST['id'] > 0) {
		$sql = "select member_id from ".TARENTO." where id={$_POST['id']}";
		$db->query($sql);
		$mid = $db->fetchField('member_id');
		$list = $tarento->get_tarento_list($mid);
	} else {
		if($_GET['member_id']>0){
			$list = $tarento->get_tarento_list($_GET['member_id'],TRUE);
		}else{
			$list = $tarento->get_tarento_list();
		}
	}
	foreach ($list as $k=>$v)
	{
		$salesInfo = $tarento->get_tarento_current_month_sales($v['member_id']);
		$list[$k]['member_num'] = $tarento->get_tarento_group_total_num($v['member_id']);
		$list[$k]['self_sales'] = $salesInfo['self_sales']?$salesInfo['self_sales']:0;
		$list[$k]['group_sales'] = $salesInfo['group_sales']?$salesInfo['group_sales']:0;
		$list[$k]['state'] = $list[$k]['member_num']>1?'closed':'open';
		$list[$k]['name'] = empty($v['name'])?'匿名用户':$v['name'];
		if($_POST['id'] > 0){
			$list[$k]['parentId'] = $_POST['id'];
		}
		$list[$k]['view'] = "<a href='?m=product&s=tarento_detail.php&id=".$v['id']."'>查看</a>&nbsp;<a class='a-opear' data-type='edit_rate' data-param=\"{'id':'".$v['id']."'}\" href='javascript:void(0);'><img src='../image/admin/set.png' /></a>";
	}
	
	echo json_encode($list);exit;
}
if($_GET['act'] && $_GET['act']=='saveInfo'){//保存
	if(!empty($_POST['data'])){
		if($_POST['data']['id']>0){
			$sql = "update ".TARENTO." set lowest_rate='{$_POST['data']['lowest_rate']}' where id={$_POST['data']['id']}";
			$db->query($sql);
			$res = array('code'=>0,'msg'=>'修改成功!');
		}else{
			$res = array('code'=>1,'msg'=>'要修改的数据不存在!');
		}
	}else{
		$res = array('code'=>2,'msg'=>'修改数据为空!');
	}
	echo json_encode($res);exit;
}

$tpl->assign("list",json_encode($de['list']));
$tpl->assign("config",$config);
$tpl->display("tarento_list.htm");
?>